package com.gxg.configure;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class FileUrlConfig
  extends WebMvcConfigurerAdapter
{
  @Value("${user.resources.url}")
  private String userResourcesUrl;
  @Value("${course.video.dir}")
  private String videoResourcesUrl;
  @Value("${course.videoImg.dir}")
  private String videoImgResourcesUrl;
  @Value("${course.videoParentImg.dir}")
  private String videoParentImgResourcesUrl;
  @Value("${video.webUrl}")
  private String videoWebUrl;
  @Value("${videoImg.webUrl}")
  private String videoImgWebUrl;
  @Value("${user.webUrl}")
  private String userWebUrl;
  @Value("${videoParentImg.webUrl}")
  private String videoParentImgWebUrl;
  public void addResourceHandlers(ResourceHandlerRegistry registry)
  {
    registry.addResourceHandler(new String[] { this.userWebUrl + "**" }).addResourceLocations(new String[] { "file:" + this.userResourcesUrl});
    registry.addResourceHandler(new String[] { this.videoImgWebUrl+ "**" }).addResourceLocations(new String[] { "file:" + this.videoImgResourcesUrl});
    registry.addResourceHandler(new String[] { this.videoWebUrl+ "**" }).addResourceLocations(new String[] { "file:" + this.videoResourcesUrl});
    registry.addResourceHandler(new String[] { this.videoParentImgWebUrl+ "**" }).addResourceLocations(new String[] { "file:" + this.videoParentImgResourcesUrl});
  }
}
